package org.paraj.masterworker;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * Created by IntelliJ IDEA.
 * User: piotrga
 * Date: Nov 20, 2008
 * Time: 8:41:57 PM
 * To change this template use File | Settings | File Templates.
 */
public class MasterImpl implements Master{
    private BlockingQueue queue = new ArrayBlockingQueue(5000, true);

    public Task getTask() {
        try {
            Task task = (Task) queue.take();
            System.out.println("Passing task to worker "+task);
            return task;
        } catch (InterruptedException e) {
            throw new RuntimeException("Master has been interrupted while waiting for task", e);
        }
    }

    public boolean schedule(Task task){
        return queue.offer(task);
    }
}
